package com.qd.common.flow.domain.config;

import com.cdqidi.dict.annotation.FieldBind;
import com.cdqidi.util.page.BaseQuery;
import com.cdqidi.valid.group.DefaultGroup;
import com.cdqidi.valid.group.DeleteGroup;
import com.cdqidi.valid.group.UpdateGroup;
import com.qd.common.dict.DictConstant;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

/**
 * 流程配置
 *
 * @author sjk
 */
@EqualsAndHashCode(callSuper = true)
@Getter
@Setter
public class FlowProcessConfigDTO extends BaseQuery {

    /**
     * 主键
     */
    @NotBlank(message = "流程ID不能为空", groups = {DeleteGroup.class, UpdateGroup.class})
    @Size(max = 50, message = "流程ID长度不能超过{max}位", groups = {DeleteGroup.class, UpdateGroup.class})
    private String processId;
    /**
     * 流程编码
     */
    @NotBlank(message = "流程编码不能为空", groups = DefaultGroup.class)
    @Size(max = 20, message = "流程编码长度不能超过{max}位", groups = DefaultGroup.class)
    private String processCode;
    /**
     * 流程名称
     */
    @NotBlank(message = "流程名称不能为空", groups = DefaultGroup.class)
    @Size(max = 200, message = "流程名称长度不能超过{max}位", groups = DefaultGroup.class)
    private String processName;
    /**
     * 添加时间
     */
    private LocalDateTime addTime;
    /**
     * 更新时间
     */
    private LocalDateTime updateTime;
    /**
     * 操作人
     */
    @FieldBind(targetField = "operatorDisplay", processName = DictConstant.SYS_PERSON)
    @Size(max = 50, message = "操作人长度不能超过{max}位", groups = DefaultGroup.class)
    private String operator;
    /**
     * 操作人姓名
     */
    private String operatorDisplay;
    /**
     * 机构ID
     */
    @Size(max = 50, message = "机构ID长度不能超过{max}位", groups = DefaultGroup.class)
    @FieldBind(targetField = "orgIdDisplay", processName = DictConstant.SYS_ORG)
    private String orgId;
    /**
     * 机构名称
     */
    private String orgIdDisplay;
    /**
     * 是否启用
     */
    @Size(max = 64, message = "是否启用长度不能超过{max}位", groups = DefaultGroup.class)
    @FieldBind(targetField = "enableDisplay")
    private String enable;
    /**
     * 是否启用显示
     */
    private String enableDisplay;
    /**
     * 流程节点配置
     */
    private List<FlowProcessNodeDTO> nodeList;

    @Override
    public void freeData() {
        this.processId = null;
        this.processCode = null;
        this.processName = null;
        this.addTime = null;
        this.updateTime = null;
        this.operator = null;
        this.operatorDisplay = null;
        this.orgId = null;
        this.enable = null;
        this.enableDisplay = null;
        Optional.ofNullable(nodeList).ifPresent(List::clear);
        super.freeData();
    }
}
